package com.wang.friend.controller;

import com.wang.api.domain.UserQuestionResultVO;
import com.wang.friend.domain.user.dto.UserSubmitDTO;
import com.wang.friend.service.IUserQuestionService;
import com.wang.common.core.controller.BaseController;
import com.wang.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户题目功能接口")
@RestController
@RequestMapping("/user/question")
public class UserQuestionController {

    @Autowired
    private IUserQuestionService userQuestionService;

    @Operation(summary = "向代码沙箱中提交代码")
    @PostMapping("/submit")
    public R<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO userSubmitDTO){
        return userQuestionService.submit(userSubmitDTO);
    }

    @Operation(summary = "使用异步功能向沙箱中提交代码")
    @PostMapping("/rabbit/submit")
    public R<Void> rabbitSubmit(@RequestBody UserSubmitDTO userSubmitDTO){
        return BaseController.toR(userQuestionService.rabbitSubmit(userSubmitDTO));
    }

    @Operation(summary = "获取判题结果")
    @GetMapping("/exe/result")
    public R<UserQuestionResultVO> exeResult(Long examId,Long questionId,String currentTime){
        return R.success(userQuestionService.exeResult(examId, questionId, currentTime));
    }
}
